/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.pod.hoteishilton.dao;

import edu.pod.hoteishilton.model.Hospede;
import java.rmi.RemoteException;
import java.util.HashMap;

/**
 *
 * @author Tigaz
 */
public class DAOHospede extends DAOFile implements IDAOHospede {

    protected static HashMap hospedes;

    public DAOHospede() throws RemoteException {
        if (hospedes == null) {
            if (getManager().getDatabase().containsKey("hospede")) {
                hospedes = getManager().getDatabase().get("hospede");
            } else {
                hospedes = new HashMap();
                getManager().getDatabase().put("hospede", hospedes);
                getManager().refresh();
            }
        }
    }

    @Override
    public void persist(Hospede hospede) throws RemoteException {
        hospedes.put(hospede.getCpf(), hospede);
        getManager().refresh();
    }

    @Override
    public void merge(Hospede hospede) throws RemoteException {
        persist(hospede);
    }

    public void remove(Hospede hospede) throws RemoteException{
        hospedes.remove(hospede.getCpf());
        getManager().refresh();
    } 
    
    @Override
    public HashMap getHospedes() throws RemoteException {
        return hospedes;
    }    
    
    @Override
    public Hospede getHospede(String cpf) throws RemoteException {
        if (hospedes.containsKey(cpf)) {
            return (Hospede) hospedes.get(cpf);
        }
        return null;
    }
}
